//bench.js
const app = getApp()
const util = require('../../../../utils/util.js')
const lbbService = require('../../../service/service.js')

Page({
  data: {
    addressList: []
  },

  onLoad: function (options) {
    this.setData({
      scrollHeight: app.getScrollHeight(0),
      applyUid: options.applyUid?options.applyUid:'',
      hospitalId: options.hospitalId?options.hospitalId:'',
    })
  },
  onReady: function () {
    let that = this
    this.personalModal = this.selectComponent("#personalModal")
  },
  onShow: function () {
    this.getReceiveAddressList();
  },
  onHide: function () {
    // Do something when page hide.
  },
  onUnload: function () {
    // Do something when page close.
  },


  getReceiveAddressList: function () {
    let that = this;
    lbbService.getReceiveAddressList({
      applyUid: that.data.applyUid,
      hospitalId: that.data.hospitalId,
    }, function (res) {
      that.setData({
        addressList: res.data,
      });
    })
  },
  addItem:function(){
    wx.navigateTo({
      url: '../addressAdd/addressAdd?applyUid='+this.data.applyUid,
    })
  },
  editItem: function (e) {
    console.log('toDetail>>', e)
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../addressAdd/addressAdd?id=' + id,
    })
  },
  deleteItem: function (e) {
    let that=this
    let id = e.currentTarget.dataset.id
    let modalText = '确定删除吗？';
    that.personalModal.showModal(modalText, function(){
      lbbService.delReceiveAddress({ id: id }, function (res) {
        that.getReceiveAddressList();
      });
    });
    
  },
  stopMaoPao:function(){
    return true;
  }, 
  selectAddress: function (e) {
    let that = this;
    console.log(e)
    let pages = getCurrentPages()
    let prevPage = pages[pages.length - 2]
    let item = e.currentTarget.dataset.item
    let selectAddress = {};
    selectAddress.receivePerson = item.receivePerson;
    selectAddress.receivePhone = item.receivePhone;
    selectAddress.receiveAddress = item.receiveAddress;
    selectAddress.id = item.id;
    prevPage.setData({
      selectAddress: selectAddress,
      selectAddressFlag: true
    })
    util.print('selectAddress',selectAddress,prevPage.data.selectAddress);
    wx.navigateBack({
      delta: 1
    })
  },
})